package com.example.orderservice.controller;

import com.example.orderservice.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: vince_zww
 * @date: 2020/7/28 21:19
 * @desceription:
 */
@RestController
@RequestMapping("/order")
public class OrderController {



    @Autowired
    private InventoryService inventoryService;
    @Autowired
    private WmsService wmsService;
    @Autowired
    private CreditService creditService;


    @RequestMapping(value = "/create", method = RequestMethod.GET)
    public String greeting(
            @RequestParam("productId") Long productId,
            @RequestParam("userId") Long userId,
            @RequestParam("count") Long count,
            @RequestParam("totalPrice") Long totalPrice) {
        System.out.println("创建订单");
        inventoryService.deductStock(productId, count);
        System.out.println("创建订单成功");
        wmsService.delivery(productId);
        System.out.println("商品发货成功");
        creditService.add(userId, totalPrice);
        System.out.println("新增积分成功");
        return "success";
    }



}
